package com.zxinglibrary.zxing.decode;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.zxinglibrary.R;



/**
 * 邮箱: ning137@foxmail.com
 *
 * 作者: njb
 *
 * 日期: 2017年2月10日
 *
 * 描述: 二维码解析管理。
 */
public class DecodeManager {

    public void showPermissionDeniedDialog(Context context) {
        // 权限在安装时被关闭了，如小米手机
        new MaterialDialog.Builder(context).title(R.string.tip_string)
                .content(R.string.camera_open_error_please_try_again_later_string)
                .autoDismiss(true)
                .positiveText(R.string.sure_string)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public void showResultDialog(Activity activity, String resultString, DialogInterface.OnClickListener listener) {
        new MaterialDialog.Builder(activity).title(R.string.tip_string)
                .content(resultString)
                .autoDismiss(true)
                .positiveText(R.string.sure_string)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public void showCouldNotReadQrCodeFromScanner(Context context, final OnRefreshCameraListener listener) {
        new MaterialDialog.Builder(context).title(R.string.tip_string)
                .content(R.string.qr_code_could_not_read_qr_code_from_scanner)
                .positiveText(R.string.qc_code_close)
                .autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                        if (listener != null) {
                            listener.refresh();
                        }
                    }
                })
                .show();
    }

    public void showCouldNotReadQrCodeFromPicture(Context context) {
        new MaterialDialog.Builder(context).title(R.string.tip_string)
                .content(R.string.qr_code_could_not_read_qr_code_from_picture)
                .positiveText(R.string.qc_code_close)
                .autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public interface OnRefreshCameraListener {
        void refresh();
    }
}
